<template>
  <div>
      <div id="loginDiv">
           <div class="putDiv">
                <i class="el-icon-user-solid"></i>
                <el-input v-model="userObj.name" placeholder="请输入用户名"></el-input>
           </div>
           <div class="putDiv">
               <i class="el-icon-lock"></i>
               <el-input v-model="userObj.pwd" show-password placeholder="请输入密码"></el-input>
           </div>
            <div id="btn">
                <el-row>                   
                        <el-button type="primary" plain @click="login">登录</el-button>                   
                        <el-button type="info" plain  @click="dump">注册</el-button>
                    </el-row>
            </div>
            <a href="https://gitee.com/oauth/authorize?client_id=f2d40ae96b2d3f7afb842cb93e3f1cd08fc13b65bbf167cf1c251cb99a1b411a&redirect_uri=http://localhost:8086/project/oauth/getcode&response_type=code">gitee</a>
      </div>
  </div>
</template>

<script>
import {mapState,mapMutations,mapActions} from "vuex"
export default {
    data(){
        return{
            userObj:{}
        }
    },
    computed:{
        ...mapState("user",["loginUser"]),
    },
    methods:{
        ...mapMutations("user",["setLoginUser"]),
        dump(){
            this.$router.push("/registe");
        },
        async login(){
           
           
                var loginObj = await this.ajax.getSubmit("/project/users/login",{name:this.userObj.name,pwd:this.userObj.pwd});
                // alert(JSON.stringify(loginObj));
                if(loginObj.status == 1){
                    // this.setLoginUser(loginObj.data);
                    this.$cookies.set("token",loginObj.data,"3d");
                    this.$cookies.set("refreshToken",loginObj.data.refreshToken,"3d");
                    this.$message({
                        message: '登录成功',
                        type: 'success'
                    });
                    this.$router.push("/menu");
                }else{
                    this.$message({
                        message: '登录失败',
                        type: 'warning'
                    });
                }
               
        }
    }

}
</script>

<style scoped>
    
    #loginDiv i {
        font-size: 35px;
    }
    .putDiv{
        width: 300px;       
        display: flex;
        margin: 0 auto;
        margin-top: 5%;
    }

    #loginDiv{
        border: 1px solid;
        border-radius: 4px;
        width: 500px;
        height: 300px;
        margin: 0 auto;
        margin-top: 5%;
    }
    #btn{
        margin-left: 30%;
        margin-top: 15%; 
    }

</style>